﻿using System;
using System.IO;

namespace NumericalSolution {
  class Convection1DMain {

    static String outfile = "c:/nsworkspace/convection1d.txt";
    static double deltax = 0.01;
    static double deltat = 0.01;
    static double endt = 1.5;

    static void Main(string[] args) {

      Convection1D sim = new Convection1DUpWind();
      sim.DeltaX = deltax;
      sim.DeltaTime = deltat;
      sim.NumberOfNodes = 150;
      sim.Type = Convection1D.WaveType.Gaussian;
      sim.Prepare();

      double[] result = null;
      while (sim.CurrentTime <= endt) {
        result = sim.Next();
      }

      StreamWriter writer = File.CreateText(outfile);
      writer.WriteLine("time=" + sim.CurrentTime);
      writer.WriteLine("x , exact, numerical");
      for (int i = 0; i < result.Length; i++) {
        writer.Write(i * deltax + ", ");
        writer.Write(u(i * deltax, sim.CurrentTime, sim) + ", ");
        writer.Write(result[i]);
        writer.WriteLine();
      }
      writer.Close();

    }

    private static double u(double x, double t, Convection1D sim) {
      double xdash = x - t / (1 + x * x);
      return sim.u(xdash);
    }

  }
}
